package com.service.impl;

import com.dao.LocationDao;
import com.entity.*;
import com.service.LocationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Created by Administrator on 2019/1/4 0004.
 */
@Service
public class LocationServiceImpl implements LocationService{
    @Autowired
    private LocationDao dao;

    @Override
    public int addLocation(Integer userId,String latitude, String longitude, String address) {
        int count = dao.findLocationCount(userId,address);
        if(count > 0){
            return 1;
        }else{
            return dao.addLocation(userId,latitude,longitude,address);
        }
    }

    @Override
    public List<CityInfo> findCity() {
        return dao.findCity();
    }

    @Override
    public List<BirthPlaceInfo> findBirthPlace() {
        return dao.findBirthPlace();
    }

    @Override
    public List<SubjectInfo> findSubject() {
        return dao.findSubject();
    }

    @Override
    public List<SchoolInfo> findSchool(String cityName) {
        String asdd = "";
        for (int a = 0; a < cityName.length(); a++) {
            asdd = String.valueOf(cityName.charAt(a));
            if (asdd.equals("市")) {
                cityName = cityName.replace("市", "");
            }
        }
        Integer cityId = dao.findCityIsBeing(cityName);
        if (cityId != null) {
            return dao.schoolList(cityId);
        } else {
            return null;
        }
    }

    @Override
    public List<SchoolInfo> findSchool1() {
        return dao.schoolList1();
    }

    @Override
    public List<AreaInfo> findArea(String cityName) {
        String asdd = "";
        for (int a = 0; a < cityName.length(); a++) {
            asdd = String.valueOf(cityName.charAt(a));
            if (asdd.equals("市")) {
                cityName = cityName.replace("市", "");
            }
        }
        Integer cityId = dao.findCityIsBeing(cityName);
        if (cityId != null) {
            return dao.findArea(cityId);
        } else {
            return null;
        }
    }

    @Override
    public List<DistrictInfo> findDistrict(Integer cityId) {
        return dao.findDistrict(cityId);
    }

    @Override
    public List<MajorInfo> findMajor() {
        return dao.findMajor();
    }
}
